import config


def has_neighbour(model, x, y, distance, count):
    start_x = x - distance
    end_x = x + distance
    start_y = y - distance
    end_y = y + distance
    for i in range(start_x, end_x + 1):
        if i < 0 or i > config.Len:
            continue
        for j in range(start_y, end_y + 1):
            if j < 0 or j > config.Len:
                continue
            if i == x and j == y:
                continue
            if model.get_pos(i, j) != config.ROLES.vacant:
                count -= 1
                if count <= 0:
                    return True
    return False
